﻿using System.Collections.Generic;
using System.Linq;
using DataBaseLayer.Dto;

namespace DataBaseLayer.Extensions
{
	public static class ImageEx
	{
		public static ImageData ToDTO(this Image entity)
		{
			if (entity == null) return null;

			var dto = new ImageData
			{
				Url = entity.Url,
				ImageId = entity.ImageId,
				GalleryId = entity.GalleryId,
				IsDefault = entity.IsDefault,
				UrlThumb = !string.IsNullOrWhiteSpace(entity.UrlThumb) ? entity.UrlThumb : entity.Url
			};

			return dto;
		}

		public static List<ImageData> ToDTOs(this IEnumerable<Image> entities)
		{
			if (entities == null) return null;

			return entities.Select(e => e.ToDTO()).ToList();
		}

	}
}
